import { uniqueId } from '@/Editor/utils/uniqueId';
import { State } from './type';
import React from 'react';
import {
  defaultCommonModalRefObject,
  ICommonModalRefObject,
} from '@/hooks/useModalRef';

export function getDefaultState(): State {
  const [id1, id2, id3, id4, id5, id6] = new Array(6).fill(0).map(uniqueId);
  return {
    nodeList: [
      {
        id: id1,
        name: id1,
        children: [
          {
            id: id2,
            name: id2,
          },
          {
            id: id3,
            name: id3,
          },
        ],
      },
      {
        id: id4,
        name: id4,
      },
      {
        id: id5,
        name: id5,
        children: [
          {
            id: id6,
            name: id6,
          },
        ],
      },
    ],
  };
}

export const GlobalContext = React.createContext<{
  modalRef: React.MutableRefObject<ICommonModalRefObject>;
  dispatch: React.Dispatch<{
    type: string;
    payload: any;
  }>;
}>({
  modalRef: {
    current: { ...defaultCommonModalRefObject },
  },
  dispatch: () => undefined,
});
